<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/page2.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
		<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.validate.min.js"></script>
	</head>
	<body>
		
		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">
			<div class="container-fluid">
				<div class="row" style="margin: 10px auto;">
					<div class="col-xs-2 text-center col-xs-offset-1"><a href="aUser.html">代理审核</a></div>
					<div class="col-xs-2 text-center"><a href="agentUserList.html">代理列表</a></div>
					<div class="col-xs-2 text-center act"><a href="aagentUserSearch.html">代理搜索</a></div>
					<div class="col-xs-2 text-center"><a href="agentUserBuy.html">购买记录</a></div>
					<div class="col-xs-2 text-center"><a href="agentUserSell.html">充值记录</a></div>
				</div>
			</div>
		
			<div class="admin_tab_cont table-responsive" style="display:block;" id="tab1">
				<section>
					<div class="input-group">
						<input type="text" class="form-control" placeholder="请输入代理ID" name="user_id">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button" id="btn">&emsp;查看&emsp;</button>
						</span>
					</div>
					
					<!--代理详细信息-->
					<div class="table-responsive">
						<table class="table" id="agentinfo" style="border: 1px solid #ddd;">
							<thead>
								<tr style="text-align: center;font-weight: bold;color: #337ab7;">
									<td colspan="8"><h4>代理详细信息</h4></td>
								</tr>
								<tr>
									<th>代理ID</th>
									<th>手机号码</th>
									<th>真实姓名</th>
									<th>代理级别</th>
									<th>推荐总数</th>
									<th>俱乐部成员数</th>
									<th>剩余{:L(GAME_RESOURCE)}</th>
									<th>总消费额</th>
									<th>总返利额</th>
									<th>待提现金额</th>
									<th>注册时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody></tbody>
						</table>
					</div>
					<!--购买详细信息-->
					<div class="table-responsive">
						<table class="table" id="buylist" style="border: 1px solid #ddd;">
							<thead>
								<tr style="text-align: center;font-weight: bold;color: #337ab7;">
									<td colspan="8"><h4>购买详细信息</h4></td>
								</tr>
								<tr>
									<th colspan="2">购买商品名称</th>
									<th colspan="2">购买商品价格</th>
									<th colspan="2">购买数量</th>
									<th colspan="2">购买时间</th>
								</tr>
							</thead>
							<tbody></tbody>
						</table>
					</div>
					<ul class="page" id="page1" style="width: 100%;overflow: hidden;"></ul>
					<!--给玩家充值的详细信息-->
					<div class="table-responsive">
						<table class="table" id="paylist" style="border: 1px solid #ddd;">
							<thead>
								<tr style="text-align: center;font-weight: bold;color: #337ab7;">
									<td colspan="8"><h4>给玩家充值详细</h4></td>
								</tr>
								<tr>
									<th colspan="2">玩家ID</th>
									<th colspan="2">充值的数量</th>
									<th colspan="2">充值状态</th>
									<th colspan="2">充值的时间</th>
								</tr>
							</thead>
							<tbody></tbody>
						</table>
					</div>
					<ul class="page" id="page2" style="width: 100%;overflow: hidden;"></ul>
					<p style="text-align: center;color: #337ab7;font-size: 18px;">给玩家充值总量统计</p>
					<p style="text-align: center;font-size: 20px;" id="total"></p>
				</section>
			</div>
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			  <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">代理设置</h4>
			      </div>
			      <div class="modal-body">
			      	<h4>说明：</h4>
			      	<div style="margin-bottom: 10px;">代理级别设置只能为1,2,3</div>
			      	<div style="margin-bottom: 10px;">重置密码不填，是原始密码，填写则是修改原始密码</div>
			      	<div class="row">
						<div class="col-md-12">
							<div class="input-group">
				                <span class="input-group-addon">代理的ID</span>
				                <input type="text" class="form-control" name="user_id" id="user_id" disabled="true">
				            </div>
				            <div class="input-group">
				                <span class="input-group-addon">重置密码</span>
				                <input type="password" class="form-control" name="repassword" id="repassword">
				            </div>
				            <div class="input-group" id="role">
				                <span class="input-group-addon">代理级别</span>
				                <div class="form-control" >
									<input type="radio"  name="role" value="1" id="role1">一级
									&emsp;
									<input type="radio"  name="role" value="2" id="role2">二级
									&emsp;
									<input type="radio"  name="role" value="3" id="role3">三级
								</div>
				            </div>
							<div class="input-group" id="state">
								<span class="input-group-addon">账号状态</span>
								<div class="form-control" >
									<input type="radio"  name="state" value="1" id="radio1">恢复
									&emsp;
									<input type="radio"  name="state" value="0" id="radio0">封号
								</div>
							</div>
						</div>
					</div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-primary" id="sbtn">保存</button>
			      </div>
			    </div>
			  </div>
			</div>
		</div>
		<script type="text/javascript">
			$("#btn").on("click",function(){
				var user_id = $(".form-control").val();
				if($.trim(user_id) == ''){
					alert("请输入要查询的代理ID!");
					return false;
				}else if(isNaN($.trim(user_id))){
					alert("代理ID是数字!");
					window.location.href="{:U('Admin/Main/agentUserSearch')}";
					return false;
				}
				$.ajax({
					type:"post",
					async:false,
					url:"{:U('Admin/Main/agentUserSearchh')}",
					dataType:"json",
					data:{'user_id':user_id},
					success:function(datas) {
						console.log(datas);
						var basic = datas.basic;
						var data1 = datas.buy;
						var data2 = datas.pay;
						if(datas != 'false') {
							//代理详细信息
							var str = "";
							var level = '';
							if(basic.role == 1) {
							    level = '一级代理';
							}else if(basic.role == 2) {
							    level = '二级代理';
							}else if(basic.role == 3) {
							    level = '三级代理';
							}
							var clubMember = '';
							if(datas.refercount == '' || datas.refercount == null) {
							    clubMember = 0;
							}else{
							    clubMember = datas.refercount;
							}
							str +="<tr><td>"+basic.user_id+"</td><td>"+basic.tel+"</td><td>"+basic.name+"</td><td>"+level+"</td><td>"+datas.count+"</td><td>"+clubMember+"</td><td>"+datas.card+"</td><td>"+basic.total_amount+"</td><td>"+basic.total_rebate+"</td><td>"+(basic.total_rebate-basic.total_withdraw)+"</td><td>"+getLocalTime(basic.create_time)+"</td><td><button class='btn btn-primary' data-toggle='modal' data-target='#myModal'>设置</button></td></tr>";
							$("#agentinfo tbody").html(str);
							$("#total tbody").html("<tr><td colspan='8'>"+basic.total_give+"</td><tr>");
							$("#total").html(basic.total_give);
							$("#user_id").val(basic.user_id);
							$("#role").val(basic.role);
							
							if(basic.role == 1) {
								$("#role1").attr("checked",true);
							}else if(basic.role == 2) {
								$("#role2").attr("checked",true);
							}else if(basic.role == 3) {
								$("#role3").attr("checked",true);
							}
							
							
							if(basic.state == 1) {
								$("#radio1").attr("checked",true);
							}else if(basic.state == 0) {
								$("#radio0").attr("checked",true);
							}
							
							//购买页面
							options={
								"id":"page1",//显示页码的元素
								"data":data1,//显示数据
							    "maxshowpageitem":2,//最多显示的页码个数
							    "pagelistcount":2,//每页显示数据个数
							    "callBack":function(res){
							    	var str = '';
							    	for(var i=0;i<res.length;i++) {
							    		str += "<tr><td colspan='2'>"+res[i].goods_name+"</td><td colspan='2'>"+res[i].amount+"</td><td colspan='2'>"+res[i].number+"</td><td colspan='2'>"+getLocalTime(res[i].add_time)+"</td></tr>";
							    	}
							    	$("#buylist tbody").html(str);
							    }
							}
							page.init(data1.length,1,options);
							
							//充值页面
							option={
								"id":"page2",//显示页码的元素
								"data":data2,//显示数据
							    "maxshowpageitem":2,//最多显示的页码个数
							    "pagelistcount":2,//每页显示数据个数
							    "callBack":function(res) {
							    	var str = '';
							    	var txt = '';
							    	for(var i=0;i<res.length;i++) {
							    		if(res[i].status == '1') {
							    			txt = '成功';
							    		}else if(res[i].status == '0') {
							    			txt = '失败';
							    		}
							    		str += "<tr><td colspan='2'>"+res[i].uid+"</td><td colspan='2'>"+res[i].number+"</td><td colspan='2'>"+txt+"</td><td colspan='2'>"+getLocalTime(res[i].add_time)+"</td></tr>";
							    	}
							    	$("#paylist tbody").html(str);
							    }
							}
							page2.init(data2.length,1,option);
						}else{
						    alert("输入的代理ID不对！");
						    window.location.href="{:U('Admin/Main/agentUserSearch')}";
						}
					}	
				});
			});
			
			$("#sbtn").on("click",function(){
				var user_id = $("#user_id").val();
				var repassword = $("#repassword").val();
				var role = $("#role input[name='role']:checked").val();
				var state = $("#state input[name='state']:checked").val();
//				console.log(user_id,repassword,role,state);
				if($.trim(repassword) == '') {
					$.ajax({
						type:"post",
						url:"{:U('Admin/Main/userInfoSet')}",
						dataType:"json",
						data:{'user_id':user_id,'role':role,'state':state},
						success:function(data) {
							if(data == 'success') {
								alert("设置成功！");
								window.location.href="{:U('Admin/Main/agentUserSearch')}";
							}else if(data == 'error'){
								alert("设置失败！");
								window.location.href="{:U('Admin/Main/agentUserSearch')}";
							}
						}
					});
				}else if($.trim(repassword) != '') {
				    if($.trim(repassword).length<6) {
				        alert("密码长度大于6位数！");
				        $("#repassword").val('');
				        return false;
					}
					$.ajax({
						url:"{:U('Admin/Main/userInfoSet')}",
						dataType:"json",
						data:{'user_id':user_id,'role':role,'state':state,'password':repassword},
						success:function(data) {
							if(data == 'success') {
								alert("设置成功！");
								window.location.href="{:U('Admin/Main/agentUserSearch')}";
							}else if(data == 'error'){
								alert("设置失败！");
								window.location.href="{:U('Admin/Main/agentUserSearch')}";
							}else if(data == 'faliure') {
							    alert("请求错误！");
							    window.location.href="{:U('Admin/Main/agentUserSearch')}";
							}
						}
					});
				}
			});
		</script>
		
	</body>
</html>
